<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <!-- <router-link to="/user_abt/user/form">
        <el-button
          type="primary"
          icon="el-icon-plus"
          style="margin-left:0px"
        >添加</el-button>
          icon="el-icon-check"
      </router-link> -->
      <el-tag type="success" style="margin:0 10px">当前状态金额统计:{{money}}</el-tag>
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      ><el-table-column align="center" prop="id" label="序号" width="70" :fixed="isMobile()?'left':undefined"/>
        <el-table-column align="center" prop="target_account" label="提现账号" width="150" />
        <el-table-column align="center" prop="target_title" label="商铺名称" width="150" />
        <el-table-column align="center" prop="money" label="提现金额" width="100" />
        <el-table-column align="center" prop="extract_way" label="提现方式" width="100" />
        <el-table-column align="center" prop="real_name" label="真实姓名" width="150" />
        <el-table-column align="center" prop="code" label="卡号账号" width="150" />
        <el-table-column align="center" prop="create_time" label="申请时间" width="200"/>
        <el-table-column align="center" prop="status" label="审核状态" width="150">
          <template slot-scope="scope">
            <el-tag
              :type="status_arr_type[scope.row.status]"
              disable-transitions
            >{{scope.row.status_str}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="remark" label="备注" />
        <el-table-column align="center" prop="reply_remark" label="回复备注" width="350" />
        <el-table-column
          align="center"
          prop="telephone"
          :fixed="isMobile()?undefined:'right'"
          width="180"
          label="操作"
        >
          <template slot-scope="scope">
            <!-- <el-button
              type="danger"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            /> -->
            <el-button
              v-if="scope.row.status == 0"
              type="primary"
              size="small"
              @click="onCheck(scope.row)"
            >审核</el-button>
            <el-button
              v-if="scope.row.status == 0"
              type="warning"
              size="small"
              style="margin-left:0px"
              @click="onUnCheck(scope.row)"
            >拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
     layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <el-dialog
      title="操作信息"
      :visible.sync="dialogVisible"
      :width="isMobile()?'80%':'30%'"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="回复备注" prop="reply_remark">
          <el-input v-model="form.reply_remark" placeholder="请输入回复备注" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onRefuse('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'cash_shop',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入名称', field: 'real_name', val: '' },
        {
          type: 'select',
          placeholder: '请选择状态',
          field: 'status',
          val: '',
          options: []
        },
        {
          type: 'select',
          placeholder: '请选择店铺',
          field: 'target_id',
          val: '',
          options: []
        },
      ],
      type: 0,
      money: 0,
      dialogVisible: false,
      form: {
        reply_remark: ''
      },
      value: '',
      selection: [],
      searchWhere: {
        title: ''
      },
      status_arr: [],
      status_arr_type: ['primary','success','warning','info'],
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14,
      rules: {
        reply_remark: [
          { required: true, message: '请输入回复备注', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      form.map.target_type = 1
      this.get('/admin/Extract/shop', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
        this.money = e.money
        if(this.status_arr.length==0){
          this.config[2].options = e.shop_list
          this.status_arr = e.status_arr
          for(let i in e.status_arr){
            this.config[1].options.push({ value: i, label: e.status_arr[i] })
          }
        }
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 删除
    // onDel(id) {
    //   this.$confirm('是否删除该记录', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     this.get('/admin/Extract/del?id=' + id, this.form, 'POST').then(e => {
    //       this.onSearch()
    //       this.$message({
    //         type: 'success',
    //         message: '删除成功!'
    //       })
    //     })
    //   }).catch(() => {
    //     this.$message({
    //       type: 'info',
    //       message: '已取消删除'
    //     })
    //   })
    // },
    onCheck(row) {
      this.type = 1

      this.selection = row.id
      this.$msg_firm('确认为店铺 "'+row.target_title+'" 提现:'+row.money+'元吗?','提现申请').then((e) =>{
        this.onCheckType(row.id)
      })
    },
    onUnCheck(row) {
      this.selection = row.id
      this.dialogVisible = true
    },
    onRefuse(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.type = 0
          this.onCheckType()
          this.dialogVisible = false
        }
      })
    },
    // 审核
    onCheckType() {
      const form =
        {
          extract_id: this.selection,
          type: this.type,
          reply_remark: this.form.reply_remark
        }
      this.get('/admin/Extract/audit_extract', form, 'POST').then(e => {
        this.onSearch()
        this.$message({
          type: 'success',
          message: '操作成功'
        })
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
